<!DOCTYPE html>
<HTML>
<HEAD>
    <TITLE>分销关系</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="/res/plugins/ztreev3/css/demo.css" type="text/css">
    <link rel="stylesheet" href="/res/plugins/ztreev3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/res/plugins/ztreev3/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.core.js"></script>
    <%if(checked!){%>
    <script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.exedit.js"></script>
    <%}%>
    <!--<script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.exedit.js"></script>-->
    <SCRIPT type="text/javascript">
        <!--
        var setting = {
            <%if(checked!){%>
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    onCheck: onCheck
                },
            <%}%>
            async: {
                enable: true,
                url:"/sys/role/resourceTree?roleId=${roleId!}",
                autoParam:["id", "name=n", "level=lv"],
                otherParam:{"otherParam":"zTreeAsyncTest"},
                dataFilter: filter
            }
        };

        <%if(checked!){%>
        function onCheck(e, treeId, treeNode) {
//                alert("[ onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name + treeNode.id+treeNode.checked);
                $.post("/sys/role/resourceRoleSet?roleId=${roleId!}",{resourceId:treeNode.id,checked:treeNode.checked,isParent:treeNode.isParent},function(data){
                    if(!data){
                        alert('设置失败')
                    }
                })
            }
        <%}%>

        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
            }
            return childNodes;
        }

        $(document).ready(function(){
            $.fn.zTree.init($("#treeDemo"), setting);
        });
        //-->
    </SCRIPT>

</HEAD>

<BODY>
        <ul id="treeDemo" class="ztree"></ul>
</BODY>
</HTML>